Get_Globals
Der Baustein REUSE_ALV_GRID_DISPLAY dient eigentlich dazu, eine Tabelle auf einfachste Art und Weise anzuzeigen. Manchmal möchte man aber doch auf die verwendete Klasse CL_GUI_ALV_GRID zugreifen können da bestimmte Funktionen nur hier und nicht im REUSE-Baustein möglich sind.
Möglich ist das durch die Verwendung des Funktionsbausteins GET_GLOBALS_FROM_SLVC_FULLSCR. Der Baustein muss in einem Caller-Exit aufgerufen werden und liefert eine Referenz auf das verwendete Grid zurück.
In diesem Beispiel zeigen wir, wie Sie mit Hilfe des Bausteins ein Kontext-Menü im REUSE-Grid verwenden können.
In dem Report wird für die Spalte “Bezeichnung” bei Rechtsklick ein Kontext-Menü eingeblendet. Der entsprechende Funktionscode wird im ALV-Exit “USER_COMMAND” ausgewertet.
Coding
REPORT. DATA gt_data TYPE STANDARD TABLE OF t005t. *----------------------------------------------------------------------* * CLASS lcl_event_receiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. CLASS-METHODS: handle_context_menu_req FOR EVENT context_menu_request OF cl_gui_alv_grid IMPORTING e_object sender. ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_context_menu_req. DATA lr_menu TYPE REF TO cl_ctmenu. DATA lr_grid TYPE REF TO cl_gui_alv_grid. DATA ls_row TYPE lvc_s_row. DATA ls_col TYPE lvc_s_col. DATA fcode TYPE ui_func. DATA ftext TYPE gui_text. DATA ls_data TYPE t005t. sender->get_current_cell( IMPORTING es_row_id = ls_row es_col_id = ls_col ). CLEAR ls_data. READ TABLE gt_data INTO ls_data INDEX ls_row-index. CASE ls_col-fieldname. WHEN 'LANDX'. *-- Kontext-Menu nur für das Feld "Bezeichnung" lr_menu ?= e_object. lr_menu->clear( ). fcode = 'EDIT'. ftext = 'Edit Entry'. lr_menu->add_function( fcode = fcode text = ftext ). fcode = 'SHOW'. CONCATENATE 'Show' ls_data-landx INTO ftext SEPARATED BY space. lr_menu->add_function( fcode = fcode text = ftext ). WHEN OTHERS. EXIT. ENDCASE. ENDMETHOD. "handle_context_menu_req ENDCLASS. "lcl_event_receiver IMPLEMENTATION START-OF-SELECTION. PERFORM get_data. PERFORM display. *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data. SELECT * FROM t005t INTO TABLE gt_data UP TO 100 ROWS WHERE spras = sy-langu. ENDFORM. "get_data *&---------------------------------------------------------------------* *& Form display *&---------------------------------------------------------------------* FORM display. DATA lt_events TYPE slis_t_event. PERFORM set_events CHANGING lt_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-cprog i_structure_name = 'T005T' it_events = lt_events TABLES t_outtab = gt_data EXCEPTIONS program_error = 1 OTHERS = 2. ENDFORM. "display *&---------------------------------------------------------------------* *& Form set_events *&---------------------------------------------------------------------* FORM set_events CHANGING ct_events TYPE slis_t_event. FIELD-SYMBOLS: <ls_event> TYPE slis_alv_event. DATA: l_event TYPE lvc_fname. CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING i_list_type = 4 IMPORTING et_events = ct_events EXCEPTIONS list_type_wrong = 1 OTHERS = 2. IF sy-subrc = 0. READ TABLE ct_events ASSIGNING <ls_event> WITH KEY name = 'CALLER_EXIT'. IF sy-subrc EQ 0. CONCATENATE 'ALV_EVENT_' <ls_event>-name INTO <ls_event>-form. ENDIF. READ TABLE ct_events ASSIGNING <ls_event> WITH KEY name = 'USER_COMMAND'. IF sy-subrc EQ 0. CONCATENATE 'ALV_EVENT_' <ls_event>-name INTO <ls_event>-form. ENDIF. ENDIF. ENDFORM. "set_events *&---------------------------------------------------------------------* *& Form alv_event_caller_exit *&---------------------------------------------------------------------* FORM alv_event_caller_exit USING cs_data TYPE slis_data_caller_exit.. DATA: lr_grid TYPE REF TO cl_gui_alv_grid. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lr_grid. SET HANDLER lcl_event_receiver=>handle_context_menu_req FOR lr_grid. ENDFORM. "alv_event_caller_exit *&---------------------------------------------------------------------* *& Form alv_event_user_command *&---------------------------------------------------------------------* FORM alv_event_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. CASE r_ucomm. WHEN 'EDIT'. MESSAGE i000(oo) WITH 'EDIT!!'. WHEN 'SHOW'. MESSAGE s000(oo) WITH 'Wurde angezeigt!'. ENDCASE. ENDFORM. "alv_event_user_command
- Interview mit Björn Schulz (Software-Heroes.com) - 3. September 2024
- Daten aus ALV ermitteln - 3. September 2024
- So lange es den SAPGUI noch gibt… - 27. Juni 2024